package com.bridgeintelligent.tag.webserver.dim.mgmt.service.scheduled;

import com.bridgeintelligent.tag.webserver.dim.mgmt.api.DepartmentRep;
import com.bridgeintelligent.tag.webserver.dim.mgmt.service.dimfree.DimFreeService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * Created by JackCheung on 2019/9/27 5:26 PM.
 */
@AllArgsConstructor
@Slf4j
@Component
public class DepartmentScheduled {

    private DepartmentScheduledService departmentScheduledService;
    private DepartmentApiUtils departmentApiUtils;
    private DimFreeService freeService;

    @Scheduled(cron = "0 0 0 * * ?")
    public void requestDepartment() {
        DepartmentApi departmentApi = departmentApiUtils.build(DepartmentApi.class);
        DepartmentRep departmentRep = departmentApi.queryDepatment();
        departmentScheduledService.updateDepartment(departmentRep);
    }

    @Scheduled(cron = "0 0 23 * * ?")
    public void doErrorFileBacup() {
        freeService.doFileBakup("error",null,null,null);
    }


}
